<template>
	<div class="train_time">
		<vue-hash-calendar
			:visible.sync="time_show"
			format="YY-MM-DD"
			:showTodayButton="false"
			:disabledWeekView="true"
			:disabled-date="disabledDate"
			pickerType="date"
			:defaultDatetime="time"
			@click="dateChange"
		></vue-hash-calendar>
	</div>
</template>
<script>
export default {
	props: {},
	data() {
		return {
			time_show: true,
			time: new Date() //只接受中国标准时间
		};
	},
	mounted() {
		if (localStorage.getItem('time')) {
			this.time = this.formatterDate(localStorage.getItem('time'));
		} else {
			this.time = new Date();
		}
	},
	methods: {
		// 禁用的日期
		disabledDate(date) {
			let timestamp = date.getTime();
			let oneDay = 24 * 60 * 60 * 1000;
			if (timestamp < new Date().getTime() - oneDay) {
				return true;
			}
			return false;
		},
		//dateChange: 是父组件指定的传数据绑定的函数，date:子组件给父组件传递的数据
		dateChange(date) {
			this.$emit('dateChange', date);
		},
		//日期转中国标准时间
		formatterDate(date) {
			let result = new Date(date);
			return result;
		}
	}
};
</script>
<style scoped lang="less">
.train_time {
	background: #fff;
	@{deep}.calendar_item {
		/*初始化背景可能会是透明的bug*/
		background: #fff !important;
	}
}
</style>
